package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumTrackListVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Parameter;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface TrackInfoMapper extends BaseMapper<TrackInfo> {


    Page<TrackListVo> findUserTrackPage(Page<TrackListVo> page, @Param("trackInfoQuery") TrackInfoQuery trackInfoQuery);

    @Select("""
            select ti.id trackId,
             ti.track_title,
             ti.media_duration,
             ti.order_num,
             max(if(ts.stat_type='0701',ts.stat_num,0)) playStatNum,
             max(if(ts.stat_type='0704',ts.stat_num,0)) commentStatNum,
             ti.create_time
             from track_info ti join track_stat ts on ti.id=ts.track_id
             where ti.album_id = #{albumId} and ti.is_open = '1' and ti.status = '0501' and ti.is_deleted = 0
             group by ti.id
            """)
    Page<AlbumTrackListVo> findAlbumTrackPage(Page<AlbumTrackListVo> page, @Param(value = "albumId")Long albumId);
}
